package com.lanyun.common.utils.bean;

import com.github.dozermapper.core.DozerBeanMapperBuilder;
import com.github.dozermapper.core.Mapper;
import com.lanyun.common.exception.BusinessException;
import java.util.*;

/**
 * @Description dozer是一个能把实体与实体之间转换的工具。类似spring的BeanUtils，但功能比BeanUtils强大，性能稍差。<br/>
 *              复杂的用DozerUtils，简单的可以继续用BeanUtils
 * @Author Jack.Zou
 * @Date 2021/5/27 23:11
 * @since:
 * @copyright:  版权所有2022 开源组织 gitee(https://gitee.com/walster)作者：Jack.Zou<br/>
 *
 */
public class DozerUtils {

    static Mapper mapper = DozerBeanMapperBuilder.buildDefault();

    /**
     * 对象拷贝
     * @param source 源对象
     * @param targetClass 目标对象
     * @param <T> 泛型
     * @return 目标对象
     */
    public static <T> T copyProperties(Object source, Class<T> targetClass){
        if (Objects.isNull(source)){
            throw new BusinessException("copyProperties对象拷贝源对象为空");
        }
        return mapper.map(source,targetClass);
    }

}
